﻿/// <reference path="Main.js" />

(function () {
    var obj = this;
    var element = $(this);
    var controls = {
        login: element,
        buttonLogin: element,
        labelButtonLogin: element,
        imageButtonLogin: element
    };
    var types = {
        TypeMode: {
            Checking: 0,
            Login: 1
        }
    };
    var currentMode = types.TypeMode.Checking;

    iuPlace.Application.OnInitialized(onInitialized);

    function onInitialized() {
        controls.login = $("#login");
        controls.buttonLogin = $("#buttonLogin").click(buttonClick);
        controls.labelButtonLogin = $("#labelButtonLogin");
        controls.imageButtonLogin = $("#imageButtonLogin");
    };

    function buttonClick() {
        if (currentMode == types.TypeMode.Login) {
            mode(types.TypeMode.Checking);
            iuPlace.Application.OpenSession(true);
        };
    };

    function mode(typeMode) {
        currentMode = typeMode;
        controls.imageButtonLogin.hide();
        if (types.TypeMode.Checking) {
            controls.labelButtonLogin.text("Verificando usuário");
            controls.imageButtonLogin.show();
        } else {
            controls.labelButtonLogin.text("Logar com Facebook");
        }
    };

    function visible(value) {
        if (value)
            controls.login.show();
        else
            controls.login.hide();
    };

    $.extend(iuPlace.Application.Mobile.Main, {
        Login: {
            Types: types,
            Mode: mode,
            Visible: visible
        }
    });
})();